﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

public class WeaponArtilleryObject : WeaponObject
{
    float m_CoolingTime = 0;

    protected override void Update()
    {
        base.Update();
        m_CoolingTime += Time.deltaTime;
    }
    public override void Fire()
    {
        var flyItemArtillery = weapon.GetSelectedFlyItem() as FlyItemArtillery;
        if(m_CoolingTime < flyItemArtillery.CalcShotFrequency())
        {
            return;
        }

        var force = (transform.rotation * -Vector3.up).normalized * flyItemArtillery.CalcEmitForce();
        m_Ship.GetComponent<Rigidbody2D>().AddForceAtPosition(force, transform.position);


        m_CoolingTime = 0;
        if (m_Weapon.flyItems.Count <= 0)
            return;
        var flyItemObject = FlyItemPool.Instance.Take(weapon, m_Weapon.GetSelectedFlyItem().flyItemID);
        flyItemObject.transform.position = transform.position + transform.up * 0.1f;
        flyItemObject.Init(ship);
        flyItemObject.Emit(this);
    }
} 